
#include "udp_sender.h"
#include <arpa/inet.h>

udp_sender::udp_sender(int port, const char *ip)
{
	m_sockfd=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
	bzero(&m_servaddr,sizeof(m_servaddr));
	m_servaddr.sin_family = AF_INET;
	m_servaddr.sin_port=htons(port);
	m_servaddr.sin_addr.s_addr=inet_addr(ip);
}
void udp_sender::send(com::Block const& flowPacket) {
	pthread_mutex_lock(&m_lock);
	std::string data;
	flowPacket.SerializeToString(&data);
	sendto(m_sockfd,data.c_str(),data.size(),0,
	       (struct sockaddr *)&m_servaddr,sizeof(m_servaddr));

	pthread_mutex_unlock(&m_lock);
	usleep(10);
}


